home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / wd.zip / WDFMT.C < prev    next >
Text File  |  1987-11-23  |  35KB  |  1,087 lines

  1.  
  2.  
  3.  
  4. /*************************************/
  5. /*                     */
  6. /*            */
  7. /*                     */
  8. /*************************************/
  9.  
  10. /*
  11.   Western Digital Corp. Format Routine
  12.  
  13.         Author: Dave Evans
  14. Edited by Tom Devlin
  15.  
  16.         Creation Date:    08/08/86
  17.         Revision Date:    7/23/87
  18.         Revision: 2.10
  19.  
  20.     Formats drive based on #cylinders, #heads, #sectors, and
  21.     interleave entered at command line or on screen.  Does low-level format
  22.     followed by a Read-verify of the entire drive.    Shows errors
  23.     detected, then allows user to enter additional blocks to
  24.     format with bad block marks.  The program may be aborted
  25.     with an Escape at both the Format prompt and at the Format
  26.     Bad Block prompt.
  27.  
  28.     Rev. 1.01   dle
  29.     Added ability to format drive D:, and also the ability to
  30.     specify the precomp cylinder.
  31.     New command line format:
  32.         WDFMT drive #cyls #heads #sectors interleave precomp-cyl
  33.  
  34.     Rev.2.00    thd
  35.     Added ability to format up to 16 heads.
  36.     fix to enable format of drive 1.
  37.     New drive spec enrty by screen:
  38.  
  39.     Rev.2.10    thd
  40.     Added Surface test, Skew, Alt sector, and made the program menu
  41.     driven. Surface test does just that. Skew is the diferance in
  42.     sector numbers on adjacent heads. Alt sector when enabled will
  43.     format an extra sector to be used in the verify if a bad sector
  44.     is found. The user can enter drive parameters on the DOS command
  45.     line or in the program.
  46.          New command line format:
  47.      WDFMT drive #cyls #heads #sectors interleave precomp-cyl skew
  48.  
  49.  
  50. */
  51.  
  52. #include <\c_ms\include\dos.h>
  53. #include <\c_ms\include\stdio.h>
  54. #include <\c_ms\include\ctype.h>
  55. #include <\c_ms\include\math.h>
  56. #include <\c_ms\include\limits.h>
  57. #include <\c_ms\include\scancode.h>
  58. #include <\c_ms\include\color.h>
  59. #include <\c_ms\include\structs.h>
  60. #include <\c_ms\include\defs.h>
  61.  
  62. /*  Global variables:
  63.  
  64.         Command parser modifies the tables, and global flags
  65.         indicate to the Main routine the requested action.
  66.  
  67. */
  68.  
  69. struct type_htable hd_table;
  70. struct type_task_file task_file;
  71. struct type_esfile;
  72. union  REGS inregs, outregs;
  73. union  type_scan scan_code;
  74. struct type_error err_table[300];
  75.  
  76. char *rd_buffer, *wr_buffer, *fmt_buffer;
  77. char head_buff[16][buf_length];
  78.  
  79. int command, err_count, errcnt, bad_count, redirection, head;
  80. unsigned char alt_value =00;       /* this is the sector # of the alt sector */
  81.  
  82.  
  83.  
  84. /******************************************/
  85. /******************************************/
  86. /******************************************/
  87. /******************************************/
  88.  
  89.  
  90.  
  91. main(argc, argv)
  92.  
  93. int argc;
  94. char *argv[];
  95.  
  96. {
  97.  
  98.     char *malloc();
  99.  
  100.     wr_buffer = malloc(buf_length);
  101.     rd_buffer = malloc(buf_length);
  102.     fmt_buffer = malloc(buf_length);
  103.  
  104. /*************************************/
  105. /*                     */
  106. /*  start of main body             */
  107. /*                     */
  108. /*************************************/
  109.  
  110.     hd_table.sec_number = 1;          /*initialize hd_table to defalt*/
  111.     hd_table.blk_size   = 1;
  112.     hd_table.max_cyl    = 615;
  113.     hd_table.max_head   = 4;
  114.     hd_table.max_sec    = 17;
  115.     hd_table.precomp    = 306;
  116.     hd_table.retry        = 0;
  117.     hd_table.step        = 0;
  118.     hd_table.ileave     = 3;
  119.     hd_table.drv_number = 0;
  120.     hd_table.skew        = 0;
  121.     hd_table.alt_sector = 0;
  122.     hd_table.ecc        = 1;        /* set for ecc in SDH reg */
  123.     hd_table.sec_size   = 0x01;        /* 01 for 512 bytes/sector */
  124.  
  125.    redirection = FALSE;             /* set redirection of input to false */
  126.    get_spec(argc, argv);            /* get specs from dos command line */
  127.    screen_update();                /* out put screen */
  128.    get_2spec();                 /* get drive specs from screen */
  129.    hd_table.max_cyl--;                /* adjust table values */
  130.    hd_table.max_head--;
  131.    hd_table.precomp = (int)((hd_table.precomp + 3)/4); /* ajust precomp */
  132.    for(head=0; head<=hd_table.max_head; head++)
  133.       do_ilt(0,head,&head_buff[head][0]);/* set up interleave for good blocks */
  134.    if(hd_table.alt_sector)
  135.       hd_table.blk_size = hd_table.max_sec - 1;
  136.    else
  137.       hd_table.blk_size = hd_table.max_sec;
  138.  
  139.    command =0;
  140.    while(TRUE)
  141.    {                        /* start of main while loop */
  142.       display_menue();                /* put menue up on screen */
  143.       command = get_command();            /* get command on what to do */
  144.       do_command(command);            /* do that command */
  145.    }                        /* end of main while loop */
  146.  
  147. }                        /* end of main body */
  148. /*************************************/
  149. /*                     */
  150. /*    eend of main body         */
  151. /*                     */
  152. /*************************************/
  153.  
  154.  
  155. /*************************************/
  156. /*                     */
  157. /*    display_menue()          */
  158. /*                     */
  159. /*  put menue on screen          */
  160. /*                     */
  161. /*************************************/
  162.  
  163. display_menue()
  164.  
  165. {                        /* start of display_menue */
  166.    upscroll(11,13,24,0,79,VNORMAL);         /* clear portion of screen */
  167.    print_atrb(13,20+h_shift," ENTER MENU CHOICE",VNORMAL);
  168.    print_atrb(15,20,"F",INVERSE);             /* print high light "F" */
  169.    print_atrb(15,21,"ormat disk  CAUTION this will destroy all data on drive !",VNORMAL);     /* print rest of format */
  170.    print_atrb(17,20,"V",INVERSE);             /* print high light "V" */
  171.    print_atrb(17,21,"erify disk",VNORMAL);     /* print rest of Verify */
  172.    print_atrb(19,20,"B",INVERSE);             /* print high light "V" */
  173.    print_atrb(19,21,"ad sector entry",VNORMAL);/* print rest of Verify */
  174.    print_atrb(21,20,"S",INVERSE);             /* print high light "S" */
  175.    print_atrb(21,21,"urface test  CAUTION this will destroy all data on drive !",VNORMAL);    /* print rest of Surface test */
  176.    print_atrb(23,20,"Q",INVERSE);             /* print high light "Q" */
  177.    print_atrb(23,21,"uit",VNORMAL);            /* print rest of Quit */
  178.  
  179.  
  180. }                        /* end of display menue */
  181.  
  182. /*************************************/
  183. /*                     */
  184. /*  get_command()             */
  185. /*                     */
  186. /*  output :  command value         */
  187. /*                     */
  188. /*************************************/
  189.  
  190. int   get_command()
  191.  
  192. {                        /* start of get_command() */
  193.    int done,old_command;
  194.    char prompt_row;
  195.    unsigned char temp_ch;
  196.  
  197.    done = FALSE;
  198.    prompt_row = 15;
  199.    old_command = command;
  200.    curs(prompt_row+(2*command),18);ARROW;   /* print arrow */
  201.    curs(prompt_row+(2*command),20);
  202.    while(!done)
  203.    {                        /* start of while */
  204.       temp_ch = get_input(redirection);     /* get input */
  205.       temp_ch = toupper(temp_ch);
  206.       switch(temp_ch)
  207.       {                     /* start of switch */
  208.      case 'F'    : old_command = command;
  209.                command = 0;        /* format */
  210.                break;
  211.      case 'V'    : old_command = command;
  212.                command = 1;        /* verify */
  213.                break;
  214.      case 'B'    : old_command = command;
  215.                command = 2;        /* bad track */
  216.                break;
  217.      case 'S'    : old_command = command;
  218.                command = 3;        /* surface */
  219.                break;
  220.      case 'Q'    : old_command = command;
  221.                command = 4;        /* quit */
  222.                break;
  223.      case CURUP  : old_command = command;
  224.                if(command EQL 0) command = 4;    /* up arrow */
  225.                else --command;
  226.                break;
  227.      case CURDN  : old_command = command;
  228.                if(command EQL 4) command = 0;     /* down arrow */
  229.                else ++command;
  230.                break;
  231.      case CRG_RTN: done = TRUE;        /* a <CR> was hit */
  232.                break;
  233.      default     : BELL;
  234.       }                     /* end of switch */
  235.       curs(prompt_row+(2*old_command),18);BLANK_SP;
  236.       curs(prompt_row+(2*command),18);ARROW;    /* print arrow */
  237.       curs(prompt_row+(2*command),20);
  238.    }                        /* end of while */
  239.    return command;                /* return command */
  240.  
  241. }                        /* end of get_command() */
  242.  
  243. /*************************************/
  244. /*                     */
  245. /*  do_command(command)          */
  246. /*                     */
  247. /*  input : command             */
  248. /*                     */
  249. /*  do the command defined by command*/
  250. /*                     */
  251.  
  252. /*************************************/
  253.  
  254. do_command(command)
  255.  
  256. int command;
  257.  
  258. {                        /* start of do_command */
  259.    switch(command)
  260.    {                        /* start of switch */
  261.       case 0 : do_format();break;        /* format disk */
  262.       case 1 : do_verify();break;        /* verify disk */
  263.       case 2 : do_bad_track(